package com.hopes.bizz.risk.tenant.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hopes.bizz.risk.setting.entity.RiskEffectEvaluationConfigEntity;
import com.hopes.bizz.risk.setting.service.RiskEffectEvaluationConfigService;
import com.hopes.bizz.risk.tenant.service.TenantConfigInitService;
import com.hopes.boss.admin.api.entity.SysTenant;
import com.hopes.boss.common.data.tenant.TenantContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/8/14 14:19
 * @Description:
 */
@Slf4j
@Service
public class RiskEffectTenantInitServiceImpl implements TenantConfigInitService {

    @Autowired
    private RiskEffectEvaluationConfigService configService;

    @Override
    public String getName() {
        return "初始化机制运行效果评估";
    }

    @Override
    public void init(SysTenant tenant) {
        Long tenantId = tenant.getId();

        List<RiskEffectEvaluationConfigEntity> configLList = configService.list(Wrappers.<RiskEffectEvaluationConfigEntity>lambdaQuery().eq(RiskEffectEvaluationConfigEntity::getTenantId, TenantContextHolder.getAdminTenantId()));
        for (RiskEffectEvaluationConfigEntity entity : configLList) {
            entity.setId(null);
            entity.setTenantId(tenantId);
        }
        configService.saveBatch(configLList);
    }
}
